<?php

declare(strict_types=1);
namespace ImiApp\ApiServer\Api\Controller\store;

use Imi\Db\Db;
use Imi\Server\Http\Route\Annotation\Action;
use Imi\Server\Http\Route\Annotation\Controller;
use Imi\Server\Http\Route\Annotation\Route;
use Psr\Http\Message\ResponseInterface;
use Imi\Aop\Annotation\Inject;
// use Phpben\Imi\Validate\Annotation\Validate;
use Phpben\Imi\Auth\Annotation\Auth;
use Imi\Config;

/**
 * 测试店铺接口💻
 * @Auth(name="token",nologin={"*"})
 * @Controller("/store.test/")
 */
class Test extends StoreBean
{

    //如果$noNeedLogin为空表示所有接口都需要登录才能请求
    //如果$noNeedRight为空表示所有接口都需要验证权限才能请求
    //如果接口已经设置无需登录,那也就无需鉴权了
    //
    // 无需登录的接口,*表示全部
    protected $noNeedLogin = ['*'];
    // 无需鉴权的接口,*表示全部
    protected $noNeedRight = ['*'];



    /**
     * 测试
     *
     * @return void
     */
    protected function test($title = '测试', $run_num = 1)
    {
        $s = $this->getMillisecond();
        for ($i = 0; $i < $run_num; $i++) {
         
        }
        $e = $this->getMillisecond();
        echo $title, '运行时间', $e - $s, '(ms);', (($e - $s) / 1000), '秒\n';
    }


    /**
     * 测试获取商品现金服务费
     * 
     * @param string $type 商品类型:normal=实物,virtual=虚拟商品,service=服务
     * @param string $goodscate_ids 商品分类id
     * @param string $goodsbrand_id 商品品牌id(可不传)
     * @param string $store_id 商户id
     * @param string $set_id 商户角色id
     * @Action
     * @return void
    */
    public function test_get_goods_service_ratio($type='normal',$goodscate_ids, $store_id = null, $set_id = null, $goodsbrand_id = null)
    {
        $data['type'] = $type;
        $data['store_id'] = $store_id;
        $data['goodscate_ids'] = $goodscate_ids;
        $data['goodsbrand_id'] = $goodsbrand_id;

        $data['goods_service_ratio'] = $this->StoreGetGoodsMoneyServerRatio($data, $set_id, $store_id);
        return $this->success($data['goods_service_ratio'],$data);
    }

    // /**
    //  * geo店铺获取id
    //  *
    //  * @return void
    //  */
    // public function geo_get_store_id()
    // {
    //     $this->UpdateStoreGeo(1,'120.111222','36.222333');

    //     $data = $this->GetStoreGeoList('120.111221','36.222331');

    //     return $this->success('',$data);
    // }

    /**
     * geo店铺获取id
     * @Action
     * @return void
     */
    public function geo_get_store_id()
    {
        // $this->UpdateStoreGeo(date('s'),'120.1112','32.2223');

        $data = $this->GetStoreGeoList('120.1112','32.2223');

        return $this->success('',$data);
    }

    /**
     * 删除全部坐标
     * @Action
     * @return void
     */
    public function del_geo_all(){
        $res = $this->geo->del_geo_all('store');
         return $this->success('',$res);
    }

    /**
     * 测试考试
     * @Action
     * @return void
     */
    public function test_exam(){
        $exam = Db::name('exam')->where('user_id', '=', 247)->where('scores', '>=', config('store_scores_pass'))->select()->get();
        var_dump($exam);
    }
}
